package com.ruoyi.omp.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.omp.api.RemoteCustomerService;
import com.ruoyi.omp.api.domain.ZsCustomer;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 客户信息降级处理
 *
 * @author ruoyi
 */
@Component
public class RemoteCustomerFactory implements FallbackFactory<RemoteCustomerService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteCustomerFactory.class);

    @Override
    public RemoteCustomerService create(Throwable throwable) {
        log.error("客户信息服务调用失败:{}", throwable.getMessage());
        return new RemoteCustomerService() {

            @Override
            public R updateCustomer(@RequestBody ZsCustomer zsCustomer) {
                return R.fail("修改客户信息失败:" + throwable.getMessage());
            }

            @Override
            public R<ZsCustomer> getCustomer(String customerId) {
                return R.fail("获取客户信息失败:" + throwable.getMessage());
            }

            @Override
            public R<ZsCustomer> getCustomerByName(String customerName) {
                return R.fail("获取客户信息失败:" + throwable.getMessage());
            }

            @Override
            public R addCustomer(ZsCustomer zsCustomer) {
                return R.fail("新增客户信息失败:" + throwable.getMessage());
            }
        };
    }
}
